<!-- <template>
  <view class="container">
    <view class="example">
      <uni-forms ref="form" :model="user" :rules="rules" labelWidth="80px">
        <uni-forms-item label="用户昵称" name="userName">
          <uni-easyinput v-model="user.userName" placeholder="请输入昵称" />
        </uni-forms-item>
        <uni-forms-item label="手机号码" name="mobile">
          <uni-easyinput v-model="user.mobile" placeholder="请输入手机号码" />
        </uni-forms-item>
      </uni-forms>
      <button type="primary" @click="submit">提交</button>
    </view>
  </view>
</template>

<script>
	import {
		findById
	} from "@/api/login"
	import {
		update
	} from "@/api/system/user"

	export default {
		data() {
			return {
				userId: this.$store.state.user.userId,
				user: {
					userName: "",
					mobile: "",
				},

				rules: {
					userName: {
						rules: [{
							required: true,
							errorMessage: '用户昵称不能为空'
						}]
					},
					mobile: {
						rules: [{
							required: true,
							errorMessage: '手机号码不能为空'
						}, {
							pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
							errorMessage: '请输入正确的手机号码'
						}]
					},
				}
			}
		},
		onLoad() {
			this.getUser()
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			getUser() {
				findById(this.userId).then(response => {
					this.user = response
				})
			},
			submit() {
				update(this.user).then(response => {
					console.log('this.user',this.user)
					console.log('response',response)
					if (response) {
						this.$store.commit('SET_NAME', this.user.userName);
						this.$modal.msgSuccess("修改成功")
					} else {
						this.$modal.msgSuccess("修改失败")
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.example {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
		flex: 1;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		line-height: 35px;
		margin-left: 10px;
	}
</style> -->